package com.oa.pm.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.joneying.common.web.response.Resp;
import com.oa.core.PageResult;
import com.oa.core.exception.DataIsEmptyException;
import com.oa.pm.dto.SocialRecruitmentChannelManagementAddDTO;
import com.oa.pm.dto.SocialRecruitmentChannelManagementListDTO;
import com.oa.pm.entity.SocialRecruitmentChannelManagement;
import com.oa.pm.service.ISocialRecruitmentChannelManagementService;
import com.oa.pm.vo.SocialRecruitmentChannelManagementListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.joneying.common.annotation.CommonController;
import org.springframework.context.annotation.Description;

import java.util.List;

import org.springframework.web.bind.annotation.RestController;
import com.oa.core.BaseController;

/**
 * @author syb123
 * @since 2019-01-22
 */
@RestController
@RequestMapping("/socialRecruitmentChannelManagement")
@Api(description = "社招渠道管理表模块")
public class SocialRecruitmentChannelManagementController extends BaseController {

    private final ISocialRecruitmentChannelManagementService socialRecruitmentChannelManagementService;

    @Autowired
    public SocialRecruitmentChannelManagementController(ISocialRecruitmentChannelManagementService socialRecruitmentChannelManagementService) {
        this.socialRecruitmentChannelManagementService = socialRecruitmentChannelManagementService;
    }

    /**
     * 查询列表
     *
     * @return Resp
     */
    @GetMapping("/list")
    @CommonController
    @Description("查询所有")
    @ApiOperation(value = "查询")
    public Resp<PageResult<SocialRecruitmentChannelManagement>> findList(SocialRecruitmentChannelManagementListDTO socialRecruitmentChannelManagementListDTO) {
        return new Resp().success(socialRecruitmentChannelManagementService.findSocialRecruitmentChannelManagementList(socialRecruitmentChannelManagementListDTO));
    }

    @GetMapping("/export")
    @CommonController
    @Description("导出")
    @ApiOperation(value = "导出")
    public void export(SocialRecruitmentChannelManagementListDTO socialRecruitmentChannelManagementListDTO) {
        socialRecruitmentChannelManagementService.export(socialRecruitmentChannelManagementListDTO, response);
    }

    /**
     * 根据Id查询
     *
     * @param id id
     * @return Resp
     */
    @GetMapping("/{id}")
    @CommonController
    @Description("获取详细信息")
    @ApiOperation(value = "根据id查询")
    public Resp<SocialRecruitmentChannelManagementListVO> findById(@ApiParam(value = "id", required = true) @PathVariable String id) {
        return new Resp().success(socialRecruitmentChannelManagementService.findSocialRecruitmentChannelManagementById(id));
    }


    /**
     * 新增
     *
     * @param socialRecruitmentChannelManagement SocialRecruitmentChannelManagement
     * @return Resp
     */
    @PostMapping("")
    @CommonController
    @Description("新增")
    @ApiOperation(value = "新增")
    public Resp add(@ApiParam(value = "社招渠道管理表对象") @RequestBody(required = false)SocialRecruitmentChannelManagementAddDTO socialRecruitmentChannelManagement) throws DataIsEmptyException {
        return socialRecruitmentChannelManagementService.add(socialRecruitmentChannelManagement);
    }

    /**
     * 根据Id修改
     *
     * @param socialRecruitmentChannelManagement SocialRecruitmentChannelManagement
     * @return Resp
     */
    @PutMapping("")
    @CommonController
    @Description("根据id修改")
    @ApiOperation(value = "根据id修改")
    public Resp update(@ApiParam(value = "社招渠道管理表对象") @RequestBody(required = false) SocialRecruitmentChannelManagementAddDTO socialRecruitmentChannelManagement) throws DataIsEmptyException {
        return socialRecruitmentChannelManagementService.edit(socialRecruitmentChannelManagement);
    }

    /**
     * 根据Id删除
     *
     * @param id id
     * @return Resp
     */
    @DeleteMapping("/{id}")
    @CommonController
    @Description("根据id删除")
    @ApiOperation(value = "根据id删除")
    public Resp delete(@ApiParam(value = "id", required = true) @PathVariable("id") String id) {
        SocialRecruitmentChannelManagement socialRecruitmentChannelManagement = socialRecruitmentChannelManagementService.selectById(id);
        if (socialRecruitmentChannelManagement != null && socialRecruitmentChannelManagement.getIsDeleted() == 2) {
            socialRecruitmentChannelManagement.setIsDeleted(1);
            if (socialRecruitmentChannelManagementService.updateById(socialRecruitmentChannelManagement)) {
                return new Resp().success();
            }
            return new Resp().failure();
        }
        return new Resp().failure();
    }
}
